package com.zzedu.controller;

import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzWordHead;
import com.zzedu.dto.ZzWordHeadDTO;
import com.zzedu.service.IZzWordHeadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 单词统计Controller
 *
 * @author Mr.Wang
 * @date 2025-03-16
 */
@RestController
@RequestMapping("/datacenter/filehead")
public class ZzWordHeadController extends BaseController {
    @Autowired
    private IZzWordHeadService zzWordHeadService;

    /**
     * 查询单词统计列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filehead:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzWordHeadDTO zzWordHead) {
        return getDataTable(zzWordHeadService.page(zzWordHead.getPageDTO(), zzWordHeadService.buildQuery(zzWordHead)));
    }

    /**
     * 导出单词统计列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filehead:export')")
    @Log(title = "单词统计", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzWordHeadDTO zzWordHead) {
        List<ZzWordHead> list = zzWordHeadService.list(zzWordHeadService.buildQuery(zzWordHead));
        ExcelUtil<ZzWordHead> util = new ExcelUtil<ZzWordHead>(ZzWordHead.class);
        util.exportExcel(ServletUtils.getResponse(), list, "单词统计数据");
    }


    /**
     * 新增保存单词统计
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filehead:add')")
    @Log(title = "单词统计", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(MultipartFile file) throws Exception {
        zzWordHeadService.doFile(file);
        return AjaxResult.success();
    }


    /**
     * 获取单词统计详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filehead:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zzWordHeadService.getById(id));
    }


    /**
     * 修改保存单词统计
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filehead:edit')")
    @Log(title = "单词统计", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzWordHead zzWordHead) {
        return toAjax(zzWordHeadService.updateById(zzWordHead));
    }

    /**
     * 删除单词统计
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filehead:remove')")
    @Log(title = "单词统计", businessType = BusinessType.DELETE)
    @RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(zzWordHeadService.removeBatchByIds(ids));
    }
}
